use std::fmt::{Debug, Display};

#[derive(Debug)]
struct Square(f32);

#[derive(Debug)]
struct Rectangle(f32, f32);

trait Area: Debug {
    fn get_area(&self) -> f32;
}

impl Area for Square {
    fn get_area(&self) -> f32 {
        self.0 * self.0
    }
}

impl Area for Rectangle {
    fn get_area(&self) -> f32 {
        self.0 * self.1
    }
}

// 特征对象作为参数
fn show_me(item: &dyn Display) {
    println!("{}", item);
}

fn main() {
    // &dyn Area 特征对象，表示执行Area特征某些实现的指针
    let shapes: Vec<&dyn Area> = vec![&Square(3f32), &Rectangle(4f32, 2f32)];
    for s in shapes {
        println!("{s:?}");
    }

    show_me(&"Hello");
}


